package com.ss.android.article.browser.website;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ss.android.article.base.feature.feed.presenter.WebArticlePreloadHelper;
import com.ss.android.article.base.feature.main.IRecentFragment;
import com.ss.android.article.base.feature.model.CategoryItem;
import com.ss.android.article.browser.BrowserPage;
import com.ss.android.article.browser.FeedFragment;
import com.ss.android.article.browser.c.SpecialPageHelper;
import com.ss.android.article.browser.main.ArticleMainActivity;
import com.ss.android.article.browser.main.ba;
import com.ss.android.article.browser.main.bean.WeatherBean;
import com.ss.android.article.browser.main.TabInspector;
import com.ss.android.article.browser.view.Browser;
import com.ss.android.article.browser.view.a.b;
import com.ss.android.browser.base.wrapper.a.BrowserSharedPreferencesWrapper;
import com.ss.android.common.app.AbsFragment;
import com.ss.android.newmedia.a.OnPageScrolledListener;

import java.util.List;

public final class a extends AbsFragment implements
        WeakHandler.Callback,
        FeedFragment,
        com.ss.android.article.browser.main.ba.a {
    private LinearLayout a;
    private TextView b;
    private TextView c;
    private TextView d;
    private TextView e;
    private TextView f;
    private RecyclerView g;
    private TextView h;
    private LinearLayout i;
    private ViewGroup j;
    private TextView k;
    private ImageView l;
    private LinearLayout m;
    private b n;
    private List o;
    private final Handler p;
    private ba q;
    private Browser r;
    private String s;
    private TabInspector t;

    public a() {
        this.p = new WeakHandler(((WeakHandler.Callback) this));
    }

    static List a(com.ss.android.article.browser.website.a arg1) {
        return arg1.o;
    }

    static List a(com.ss.android.article.browser.website.a arg0, List arg1) {
        arg0.o = arg1;
        return arg1;
    }

    public final void onProgressChanged(int newProgress) {
    }

    public final void onNewIntent(Bundle bundle) {
    }

    public final void onCreateWindow(Message message) {
    }

    public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
    }

    public final void onShowCustomView(View arg1, WebChromeClient.CustomViewCallback customViewCallback, int requestedOrientation) {
    }

    public final void onShowFileChooser(ValueCallback valueCallback) {
    }

    public final void setOnPageScrolledListener(OnPageScrolledListener arg1) {
    }

    public final void loadUrl(String arg2) {
        if (SpecialPageHelper.a(arg2)) {
            this.n();
            this.r.loadUrl(arg2);
        }
    }

    public final void loadUrl(String arg3, String arg4) {
        String v0 = arg3.trim();
        Browser v1 = this.r;
        if (v1 != null) {
            v1.c();
            this.r.loadUrl(SpecialPageHelper.a(v0, arg4));
            this.r.clearHistory();
        }
    }

    public final void addDelayInitCallback(DelayInitCallback delayInitCallback) {
    }

    public final void addIRecentFragment(IRecentFragment recentFragment) {
    }

    public static com.ss.android.article.browser.website.a b(Bundle arg1) {
        com.ss.android.article.browser.website.a v0 = new com.ss.android.article.browser.website.a();
        v0.setArguments(arg1);
        return v0;
    }

    static LinearLayout b(com.ss.android.article.browser.website.a arg1) {
        return arg1.m;
    }

    public final void b() {
    }

    public final void b(String arg1) {
    }

    public final void b(boolean arg1) {
    }

    public final void setCanGoForward(boolean canGoForward) {
    }

    static ba c(com.ss.android.article.browser.website.a arg1) {
        return arg1.q;
    }

    public final void c() {
    }

    public final void setCanGoBack(boolean canGoBack) {
    }

    public final boolean canShowNotify() {
        return false;
    }

    static Browser d(com.ss.android.article.browser.website.a arg1) {
        return arg1.r;
    }

    public final Browser d() {
        return null;
    }

    public final void onMenuTabClick(boolean arg4) {
        if (this.q != null) {
            this.q.a(false);
        }

        if (this.r != null) {
            this.r.c();
            this.r.setWebViewVisibility(8);
        }

        UIUtils.setVisibility(this.a, 0);
        BrowserPage v0 = this.t.mBrowserPage;
        if (v0 != null) {
            v0.onPageChangedEnd(false);
        }
    }

    public final boolean doBackPressRefresh() {
        return false;
    }

    public final void e() {
    }

    public final void f() {
    }

    public final void g() {
    }

    public final String getCategory() {
        return null;
    }

    public final Fragment getCurrentFragment() {
        return null;
    }

    public final void getCurrentList(int arg1, List result) {
    }

    public final int getFirstVisiblePosition() {
        return 0;
    }

    public final WebArticlePreloadHelper getPreloadHelper() {
        return null;
    }

    public final boolean getUseTabTip() {
        return false;
    }

    public final void h() {
    }

    public final void handleCategoryTip(String category, String tip, String count) {
    }

    public final void handleMsg(Message message) {
        switch (message.what) {
            case 10: {
                if ((message.obj instanceof WeatherBean)) {
                    Object v0 = message.obj;
                    this.b.setText(String.format("%s°", Integer.valueOf(((WeatherBean) v0).current_temperature)));
                    this.c.setText(((WeatherBean) v0).city_name);
                    this.d.setText(((WeatherBean) v0).current_condition);
                    this.f.setText("空气质量: " + ((WeatherBean) v0).quality_level);
                    this.e.setText("PM2.5: " + ((WeatherBean) v0).aqi);
                }

                break;
            }
        }
    }

    public final int i() {
        return 0;
    }

    public final boolean isPrimaryPage(IRecentFragment recentFragment) {
        return false;
    }

    public final boolean isViewCategory() {
        return false;
    }

    public final boolean j() {
        return false;
    }

    public final boolean k() {
        return false;
    }

    public final String getUrl() {
        return null;
    }

    public final boolean m() {
        boolean v0 = false;
        Browser v2 = this.r;
        if (v2 != null) {
            if (this.q != null && (this.q.b())) {
                this.q.a(false);
                UIUtils.setVisibility(this.a, 0);
                return true;
            }

            if (!v2.isWebViewVisible()) {
                return v0;
            }

            if (v2.canGoBack()) {
                v2.goBack();
                return true;
            }

            this.onMenuTabClick(false);
        }

        return v0;
    }

    public final void n() {
        if (this.q != null) {
            this.q.a(false);
        }

        this.r.setWebViewVisibility(0);
    }

    public final boolean o() {
        return false;
    }

    public final void onActivityCreated(@Nullable Bundle arg1) {
        super.onActivityCreated(arg1);
    }

    public final void onBackPressRefresh() {
    }

    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    }

    @Nullable
    public final View onCreateView(LayoutInflater arg3, @Nullable ViewGroup arg4, @Nullable Bundle arg5) {
        return arg3.inflate(com.ss.android.article.browser.R.layout.dw, arg4, false);
    }

    public final void onLastReadShow() {
    }

    public final void onListViewScrollStateChanged(int arg1) {
    }

    public final void onLoadingStatusChanged(IRecentFragment arg1) {
    }

    public final void onResume() {
        super.onResume();
        if (this.q != null) {
            this.q.a();
        }
    }

    public final void onUserPullToRefresh() {
    }

    public final void onViewCreated(View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        this.a = view.findViewById(com.ss.android.article.browser.R.id.main_page);
        view.findViewById(com.ss.android.article.browser.R.id.vh);
        view.findViewById(com.ss.android.article.browser.R.id.ll_weather_container);
        this.b = view.findViewById(com.ss.android.article.browser.R.id.tv_weather_temperature);
        this.c = view.findViewById(com.ss.android.article.browser.R.id.tv_weather_city);
        this.d = view.findViewById(com.ss.android.article.browser.R.id.tv_weather_status);
        this.e = view.findViewById(com.ss.android.article.browser.R.id.tv_weather_pm2_5);
        this.f = view.findViewById(com.ss.android.article.browser.R.id.tv_air_quality);
        this.g = view.findViewById(com.ss.android.article.browser.R.id.vp);
        this.h = view.findViewById(com.ss.android.article.browser.R.id.tv_search_box);
        this.i = view.findViewById(com.ss.android.article.browser.R.id.ll_search_root);
        this.i.findViewById(com.ss.android.article.browser.R.id.ll_search_box);
        this.i.findViewById(com.ss.android.article.browser.R.id.listview_search_history);
        this.j = view.findViewById(com.ss.android.article.browser.R.id.browser_container);
        this.k = view.findViewById(com.ss.android.article.browser.R.id.browser_page_fake_input_tv);
        this.l = view.findViewById(com.ss.android.article.browser.R.id.browser_page_refresh_iv);
        this.m = view.findViewById(com.ss.android.article.browser.R.id.browser_page_header);
        view.findViewById(com.ss.android.article.browser.R.id.browser_page_loading_progress);
        this.t = TabInspector.getInstance();
        this.n = new b();
        this.g.setAdapter(this.n);
        this.g.setLayoutManager(new GridLayoutManager(this.g.getContext(), 4));
        this.g.addItemDecoration(new com.ss.android.article.browser.view.a.a(2));
        this.q = new ba(this.getContext(), this.i, this);
        this.q.c = ((com.ss.android.article.browser.main.ba.a) this);
        Bundle v0 = this.getArguments();
        if (v0 != null) {
            this.s = v0.getString("bundle_url");
        }

        ((ArticleMainActivity) this.getActivity()).getPresenter().a(this.p);
        String v0_1 = BrowserSharedPreferencesWrapper.getString("website_list", null);
        if (TextUtils.isEmpty(v0_1)) {
            android.support.design.a.createBrowserISApi().getNavigationBar("").enqueue(new com.ss.android.article.browser.website.e(this));
        } else {
            this.o = (List) new Gson().fromJson(v0_1, new TypeToken<List<NavigationBean>>() {
            }.getType());
            this.w();
        }

        this.r = new Browser(this.getActivity(), this, false);
        WebView v1 = this.r.getWebView();
        if (v1 != null) {
            ViewParent v0_2 = ((View) v1).getParent();
            if ((v0_2 instanceof ViewGroup)) {
                ((ViewGroup) v0_2).removeView(((View) v1));
            }
        }

        if (this.j != null) {
            this.j.addView(((View) v1), 0);
        }

        if (this.m != null) {
            this.m.getViewTreeObserver().addOnPreDrawListener(new f(this, v1));
        }

        this.r.a(this.k);
        if (this.k != null) {
            this.k.setOnClickListener(new com.ss.android.article.browser.website.g(this));
        }

        if (this.l != null) {
            this.l.setOnClickListener(new com.ss.android.article.browser.website.h(this));
        }

        if (!TextUtils.isEmpty(this.s)) {
            this.n();
            this.r.loadUrl(this.s);
        }

        this.h.setOnClickListener(new com.ss.android.article.browser.website.b(this));
        this.n.b = new com.ss.android.article.browser.website.c(this);
    }

    public final boolean p() {
        return false;
    }

    public final String q() {
        return null;
    }

    public final boolean q_() {
        return false;
    }

    public final void onHideCustomView() {
    }

    public final void removeDelayInitCallback(DelayInitCallback delayInitCallback) {
    }

    public final void onGoBackClick() {
        this.m();
    }

    public final boolean showTipsFor(String arg2) {
        return false;
    }

    public final void switchCategory(CategoryItem categoryItem, int arg2) {
    }

    public final void onGoNextClick() {
    }

    public final void onPageStarted() {
        UIUtils.setVisibility(this.l, 0);
        if (this.l != null) {
            this.l.setImageResource(com.ss.android.article.browser.R.drawable.rb);
        }

        if (this.t == null) {
            this.t = TabInspector.getInstance();
        }
        BrowserPage v0 = this.t.mBrowserPage;
        if (v0 != null) {
            v0.onPageChangedStart(true);
        }
    }

    public final void updateCategoryTip(String arg1) {
    }

    public final void onPageFinished() {
    }

    public final void w() {
        int v3 = 20;
        if (this.o.size() > v3) {
            this.n.a(this.o.subList(0, v3));
        } else {
            this.n.a(this.o);
        }
    }

    public final void x() {
        if (this.q != null) {
            this.q.a(true);
        }

        UIUtils.setVisibility(this.a, 8);
    }
}

